import {Component, Input, OnDestroy, OnInit, ViewEncapsulation} from '@angular/core';


import {Subject} from "rxjs/Subject";
import {MatchService} from "../../match.service";
import {MatchInfoResp} from "@interface/index";



@Component({
  selector: 'match-description',
  templateUrl: './match-description.component.html',
  styleUrls: ['./match-description.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class MatchDescriptionComponent implements OnInit, OnDestroy {
  @Input() matchId;

  public info: MatchInfoResp;
  public stateStore = {
    haveData: true
  };
  public ngUnsubscribe: Subject<any> = new Subject<any>();

  constructor(public service: MatchService) {
  }

  /**
   * @description 获取赛事详情详情信息
   * @author ouyqx-691
   */
  getCompetitionInfo() {
    this.service.getCompetitionInfo(this.matchId).takeUntil(this.ngUnsubscribe).subscribe(res => {
      if (res.result === '0' && res.data) {
        this.info = res.data;
      } else {
        this.stateStore.haveData = false;
      }
    });
  }

  ngOnInit() {
  }

  ngOnDestroy() {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }
}
